float4x4 World;
float4x4 ViewProjection;

sampler DecalFar : register(s0);
sampler Mask : register(s2);

float4 SampleTextures(float2 coordinate)
{
	return tex2D(DecalFar, coordinate);
}

void VertexShaderFunction(float4 inPosition : POSITION0,
							float2 inTexCoord : TEXCOORD0,
							float3 inAux : NORMAL0,
							out float outRadius : PSIZE0,
							out float4 outPosition : POSITION0,
							out float2 outTexCoord : TEXCOORD0,
							out float3 outColor : COLOR
)
{
    float4 worldPosition = mul(inPosition, World);
    outPosition = mul(worldPosition, ViewProjection);
    outRadius = inAux.y / outPosition.z;
    
    outTexCoord = inTexCoord;
    outColor = inAux.x;
}


float4 PixelShaderFunction(float4 inPosition : POSITION0,
							float2 inTexCoord : TEXCOORD0,
							float inRadius : PSIZE,
							float3 inColor : COLOR) : COLOR0
{
	float4 octave0 = SampleTextures(inTexCoord);
	float4 octave1 = SampleTextures(inTexCoord * 2) - 0.5f;
	float4 octave2 = SampleTextures(inTexCoord * 4) - 0.5f;
	float4 octave3 = SampleTextures(inTexCoord * 8) - 0.5f;
	float4 octave4 = SampleTextures(inTexCoord * 16) - 0.5f;
	float4 octave5 = SampleTextures(inTexCoord * 32) - 0.5f;
	
	float4 noise = (1.0f * octave0) + 
	//0.50f * (0.5f * octave1) + 
	//(0.25f * octave2) + 
	//(0.125f * octave3) + 
	//(0.0625f * octave4) + 
	//(0.03125f * octave5) +
	0;
	
	float variation = inColor.x*0.1;
	
	float3 colorA = lerp(float3(0.8, 0.45, 0.8) * inColor.xyz, float3(0.83,0.72,0.183),  inTexCoord.y + variation);
	
	float4 color = float4(colorA.xyz,0);
	color.w = dot(noise.xyz * tex2D(Mask, inTexCoord), float3(0.33f,0.33f,0.33f));
	 
    return color;
}

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
